<template>
  <el-dialog title="填写跟进记录" :visible.sync="dialogFormVisible">
    <el-form ref="createfollowrecord" :model="creator" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item>
            <span>咨询人：{{ receptionInfo.consultantName }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item>
            <span>老人姓名：{{ receptionInfo.elderlyName }}</span>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="跟进内容" :rules="[
      { required: true, message: '请输入跟进内容', trigger: 'blur' },
    ]">
            <el-input type="textarea" v-model="creator.followUpContent"></el-input>
          </el-form-item>
        </el-col>

      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="咨询意向" :rules="[
      { required: true, message: '请选择咨询意向', trigger: 'blur' },
    ]">
            <el-select v-model="creator.consultationIntention" placeholder="请选择咨询意向">
              <el-option v-for="item in readyData.consultationIntention" :label="item.name" :value="item.dcNo" :key="item.dcNo"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item>
            <span>接待状态：{{ receptionInfo.receptionStatusName }}</span>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="saveRecord">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {findAllDictionaryWithChild} from "@/api/dict"
  import {saveFollowUpRecord} from "@/api/followrecord"
  import { parseTime} from "@/utils/index";

    export default {
        name: "",
        filters:{
                  parseTime:parseTime
                },
        data(){
          return {
            dialogFormVisible: false,
            creator: {
              "consultationIntention": undefined,
              "followUpContent": undefined
            },
            receptionInfo: {},
            readyData: {
              consultationIntention: []
            }
          }
        },
        methods: {
          show(row){
              this.creator.followUpContent=""

              this.creator.consultationIntention=""
            this.receptionInfo = row
            this.dialogFormVisible = true
          },
          searchDictInfo(){
            findAllDictionaryWithChild().then(result => {
              if(result.code == "200"){
                if(result.data!=null){
                  for(let index in result.data){
                    let item = result.data[index]
                    if(item.mark == 'consultationIntention'){
                      this.readyData.consultationIntention = item.childs
                      break;
                    }
                  }
                }
              }
            })
          },
          saveRecord(){
            this.$refs["createfollowrecord"].validate(async (valid) => {
              if (valid) {
                const data = await saveFollowUpRecord(this.receptionInfo.code, this.creator);
                if(data.code == "200") {
                  this.$baseMessage("添加成功");
                    this.$parent.search()
                  this.dialogFormVisible = false
                } else {
                  this.$baseMessage("添加失败，"+data.message);
                }
              } else {
                return false;
              }
            });
          }
        },
      mounted(){
        this.searchDictInfo()
      }
    }
</script>

<style scoped>

</style>
